using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Library;
using NCS.Library.Components.Portal;
using NCS.Library.Components.Security;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library.Definitions;
using NCS.Module.CMS.Library.Zones;

namespace NCS.Module.CMS.Admin
{
    public partial class TTSetting : AuthenticatedControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                dropPortalTT.DataSource = PortalController.GetPortalsByLang(AppEnv.GetLanguage());
                dropPortalTT.DataBind();
            }
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            //tin tuc
            dropHomenew.Items.Clear();
            dropnewest.Items.Clear();
            dropfocus.Items.Clear();
            dropphongsu.Items.Clear();
            dropHotNews.Items.Clear();
            dropproblem.Items.Clear();

            dropTTTinNoiBat.Items.Clear();
            dropTT_TinNoiBat_Position1.Items.Clear();
            dropTT_TinNoiBat_Position2.Items.Clear();
            
            dropTTTinMoiNhan.Items.Clear();
            dropTT_TinMoiNhan_Position1.Items.Clear();
            dropTT_TinMoiNhan_Position2.Items.Clear();
            
            dropTTTinTieuDiem.Items.Clear();
            dropTT_TinTieuDiem_Position1.Items.Clear();
            dropTT_TinTieuDiem_Position2.Items.Clear();
            
            dropTTVanDeDuLuan.Items.Clear();
            dropTT_VanDeDuLuan_Position1.Items.Clear();
            dropTT_VanDeDuLuan_Position2.Items.Clear();
            
            dropTTClipDacSac.Items.Clear();
            dropTT_ClipDacSac_Position1.Items.Clear();
            dropTT_ClipDacSac_Position2.Items.Clear();
            
            dropTTPhongSuKySu.Items.Clear();
            dropTT_PhongSuKySu_Position1.Items.Clear();
            dropTT_PhongSuKySu_Position2.Items.Clear();
            
            int ptt = ConvertUtility.ToInt32(Portal[Constants.CMS_PortalTT + AppEnv.GetLanguage()]);
            if (ptt > 0)
            {
                MiscUtility.SelectItemFromList(dropPortalTT, ptt.ToString());
            }
            else
            {
                MiscUtility.SelectItemFromList(dropPortalTT, ConvertUtility.ToString(Request.QueryString["portalid"]));
            }

            ZoneController.LoadZones(dropHomenew.Items, dropPortalTT.SelectedValue);

            //tin tuc
            foreach (ListItem item in dropHomenew.Items)
            {
                dropnewest.Items.Add(new ListItem(item.Text, item.Value));
                dropfocus.Items.Add(new ListItem(item.Text, item.Value));
                dropproblem.Items.Add(new ListItem(item.Text, item.Value));
                dropHotNews.Items.Add(new ListItem(item.Text, item.Value));
                dropphongsu.Items.Add(new ListItem(item.Text, item.Value));
                
                //trang cap 2 va chi tiet
                dropTTTinNoiBat.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_TinNoiBat_Position1.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_TinNoiBat_Position2.Items.Add(new ListItem(item.Text, item.Value));

                dropTTTinMoiNhan.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_TinMoiNhan_Position1.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_TinMoiNhan_Position2.Items.Add(new ListItem(item.Text, item.Value));

                dropTTTinTieuDiem.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_TinTieuDiem_Position1.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_TinTieuDiem_Position2.Items.Add(new ListItem(item.Text, item.Value));

                dropTTVanDeDuLuan.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_VanDeDuLuan_Position1.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_VanDeDuLuan_Position2.Items.Add(new ListItem(item.Text, item.Value));

                dropTTClipDacSac.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_ClipDacSac_Position1.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_ClipDacSac_Position2.Items.Add(new ListItem(item.Text, item.Value));

                dropTTPhongSuKySu.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_PhongSuKySu_Position1.Items.Add(new ListItem(item.Text, item.Value));
                dropTT_PhongSuKySu_Position2.Items.Add(new ListItem(item.Text, item.Value));
            }
            int zonehomenew = ConvertUtility.ToInt32(Portal[Constants.CMS_HomeNew + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropHomenew, zonehomenew.ToString());

            int newest = ConvertUtility.ToInt32(Portal[Constants.CMS_TinMoiNhan + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropnewest, newest.ToString());

            int focus = ConvertUtility.ToInt32(Portal[Constants.CMS_TieuDiem + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropfocus, focus.ToString());

            int phongsu = ConvertUtility.ToInt32(Portal[Constants.CMS_Phongsu_Kysu + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropphongsu, phongsu.ToString());

            int tinnoibat = ConvertUtility.ToInt32(Portal[Constants.CMS_TinNoiBat + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropHotNews, tinnoibat.ToString());

            int vande = ConvertUtility.ToInt32(Portal[Constants.CMS_Vande_duluan + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropproblem, vande.ToString());
            
            //trang cap 2 va chi tiet
            
            // tin noi bat
            int Level2_TinNoiBat = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_TinNoiBat + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTTTinNoiBat, Level2_TinNoiBat.ToString());

            int CMS_Level2_TinNoiBat_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + Level2_TinNoiBat + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_TinNoiBat_Position1, CMS_Level2_TinNoiBat_Position1.ToString());

            int CMS_Level2_TinNoiBat_Position2 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position2 + Level2_TinNoiBat + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_TinNoiBat_Position2, CMS_Level2_TinNoiBat_Position2.ToString());
            
            //tin moi nhan
            int Level2_TinMoiNhan = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_TinMoiNhan + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTTTinMoiNhan, Level2_TinMoiNhan.ToString());

            int CMS_Level2_TinMoiNhan_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + Level2_TinMoiNhan + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_TinMoiNhan_Position1, CMS_Level2_TinMoiNhan_Position1.ToString());

            int CMS_Level2_TinMoiNhan_Position2 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position2 + Level2_TinMoiNhan + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_TinMoiNhan_Position2, CMS_Level2_TinMoiNhan_Position2.ToString());
            
            //tin tieu diem
            int CMS_Level2_TieuDiem = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_TieuDiem + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTTTinTieuDiem, CMS_Level2_TieuDiem.ToString());

            int CMS_Level2_TieuDiem_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + CMS_Level2_TieuDiem + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_TinTieuDiem_Position1, CMS_Level2_TieuDiem_Position1.ToString());

            int CMS_Level2_TieuDiem_Position2 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position2 + CMS_Level2_TieuDiem + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_TinTieuDiem_Position2, CMS_Level2_TieuDiem_Position2.ToString());
            
            //van de du luan
            int CMS_Level2_Vande_duluan = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Vande_duluan + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTTVanDeDuLuan, CMS_Level2_Vande_duluan.ToString());

            int CMS_Level2_Vande_duluan_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + CMS_Level2_Vande_duluan + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_VanDeDuLuan_Position1, CMS_Level2_Vande_duluan_Position1.ToString());

            int CMS_Level2_Vande_duluan_Position2 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position2 + CMS_Level2_Vande_duluan + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_VanDeDuLuan_Position2, CMS_Level2_Vande_duluan_Position2.ToString());
           
            //clip dac sac
            int CMS_Level2_Clip_dacsac = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Clip_dacsac + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTTClipDacSac, CMS_Level2_Clip_dacsac.ToString());

            int CMS_Level2_Clip_dacsac_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + CMS_Level2_Clip_dacsac + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_ClipDacSac_Position1, CMS_Level2_Clip_dacsac_Position1.ToString());

            int CMS_Level2_Clip_dacsac_Position2 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position2 + CMS_Level2_Clip_dacsac + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_ClipDacSac_Position2, CMS_Level2_Clip_dacsac_Position2.ToString());
           
            //phong su ky su
            int CMS_Level2_Phongsu_Kysu = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Phongsu_Kysu + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTTPhongSuKySu, CMS_Level2_Phongsu_Kysu.ToString());

            int CMS_Level2_Phongsu_Kysu_Position1 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position1 + CMS_Level2_Phongsu_Kysu + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_PhongSuKySu_Position1, CMS_Level2_Phongsu_Kysu_Position1.ToString());

            int CMS_Level2_Phongsu_Kysu_Position2 = ConvertUtility.ToInt32(Portal[Constants.CMS_Level2_Position2 + CMS_Level2_Phongsu_Kysu + "_" + AppEnv.GetLanguage()]);
            MiscUtility.SelectItemFromList(dropTT_PhongSuKySu_Position2, CMS_Level2_Phongsu_Kysu_Position2.ToString());
           
        }
        protected void btnUpdateTintuc_Click(object sender, EventArgs e)
        {
            try
            {
                PortalSetting.SetValue(Constants.CMS_HomeNew + AppEnv.GetLanguage(), dropHomenew.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_TinMoiNhan + AppEnv.GetLanguage(), dropnewest.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_TieuDiem + AppEnv.GetLanguage(), dropfocus.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Phongsu_Kysu + AppEnv.GetLanguage(), dropphongsu.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Vande_duluan + AppEnv.GetLanguage(), dropproblem.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_TinNoiBat + AppEnv.GetLanguage(), dropHotNews.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_PortalTT + AppEnv.GetLanguage(), dropPortalTT.SelectedValue);

                //trang cap 2 va chi tiet
                PortalSetting.SetValue(Constants.CMS_Level2_TinNoiBat + AppEnv.GetLanguage(), dropTTTinNoiBat.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropTTTinNoiBat.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_TinNoiBat_Position1.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position2 + dropTTTinNoiBat.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_TinNoiBat_Position2.SelectedValue);
                
                PortalSetting.SetValue(Constants.CMS_Level2_TinMoiNhan + AppEnv.GetLanguage(), dropTTTinMoiNhan.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropTTTinMoiNhan.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_TinMoiNhan_Position1.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position2 + dropTTTinMoiNhan.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_TinMoiNhan_Position2.SelectedValue);
                
                PortalSetting.SetValue(Constants.CMS_Level2_TieuDiem + AppEnv.GetLanguage(), dropTTTinTieuDiem.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropTTTinTieuDiem.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_TinTieuDiem_Position1.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position2 + dropTTTinTieuDiem.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_TinTieuDiem_Position2.SelectedValue);
                
                PortalSetting.SetValue(Constants.CMS_Level2_Vande_duluan + AppEnv.GetLanguage(), dropTTVanDeDuLuan.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropTTVanDeDuLuan.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_VanDeDuLuan_Position1.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position2 + dropTTVanDeDuLuan.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_VanDeDuLuan_Position2.SelectedValue);
                
                PortalSetting.SetValue(Constants.CMS_Level2_Clip_dacsac + AppEnv.GetLanguage(), dropTTClipDacSac.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropTTClipDacSac.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_ClipDacSac_Position1.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position2 + dropTTClipDacSac.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_ClipDacSac_Position2.SelectedValue);
                
                PortalSetting.SetValue(Constants.CMS_Level2_Phongsu_Kysu + AppEnv.GetLanguage(), dropTTPhongSuKySu.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position1 + dropTTPhongSuKySu.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_PhongSuKySu_Position1.SelectedValue);
                PortalSetting.SetValue(Constants.CMS_Level2_Position2 + dropTTPhongSuKySu.SelectedValue + "_" + AppEnv.GetLanguage(), dropTT_PhongSuKySu_Position2.SelectedValue);

                lblUpdateStatus.Text = MiscUtility.MSG_UPDATE_SUCCESS;
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

    }
}